package com.idanchuang.database.manage.controller;


import com.alibaba.druid.pool.DruidDataSource;
import com.idanchuang.component.base.JsonResult;
import com.idanchuang.database.manage.config.DynamicDataSource;
import com.idanchuang.database.manage.model.Connection;
import com.idanchuang.database.manage.model.UserInfo;
import com.idanchuang.database.manage.service.ConnectService;
import com.idanchuang.database.manage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聚合层接口样例
 * @author yjy
 * @date 2020/5/14 13:03
 **/
@RestController
public class ConnectController {

    @Autowired
    private ConnectService connectService;

    @Autowired
    private UserService userService;

    @GetMapping("/getAll")
    public Object test(){
        List<UserInfo> all = userService.list();
        return all;
    }

    @PostMapping("/connectDB")
    public JsonResult<Boolean> connectDB(@RequestBody Connection connection) {
        Boolean conn=connectService.connectDB(connection);
        return JsonResult.success(conn);
    }


    @GetMapping("/test")
    public Object test(Connection connection) {
        Boolean conn=connectService.connectDB(connection);
        if(conn){
            List<UserInfo> all = userService.list();
            return all;
        }
        return JsonResult.success(conn);
    }

}
